CXX       = g++
CXX_FLAGS = -O2 -Wall -Wextra -Warray-bounds -MMD -MP 
ifdef DEBUG
CXX_FLAGS += -g
endif
SRC_DIR   	= .
INC_DIR   	= .
BUILD_DIR 	= build_make
OBJ_DIR   	= obj
LIBRARIES   =
EXECUTABLE  = task1

SRC     = $(wildcard $(SRC_DIR)/*.cpp)
INC     = -I$(INC_DIR)
OBJ     = $(addprefix $(BUILD_DIR)/$(OBJ_DIR)/,$(notdir $(SRC:.cpp=.o)))
DEPENDS = $(addprefix $(BUILD_DIR)/$(OBJ_DIR)/,$(notdir $(SRC:.cpp=.d)))


vpath %.cpp $(sort $(dir $(SRC)))
.PHONY: clean

all: $(BUILD_DIR)/$(EXECUTABLE)

-include $(DEPENDS)

$(BUILD_DIR)/$(OBJ_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
	$(CXX) $(CXX_FLAGS) $(INC) -c $< -o $@ $(LIBRARIES)

$(BUILD_DIR)/$(EXECUTABLE): $(OBJ)
	$(CXX) $(CXX_FLAGS) $(INC) $(OBJ) -o $@

$(BUILD_DIR):
	mkdir $@
	mkdir $@/$(OBJ_DIR)

clean:
	rm $(BUILD_DIR)/$(EXECUTABLE) $(OBJ) $(DEPENDS)
